package com.fr.privilege.allocation;

import com.fr.base.XMLable;
import com.fr.base.core.list.IntList;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import java.util.ArrayList;
import java.util.List;

public class Allocation
  implements XMLable
{
  private static final long serialVersionUID = -2914825417693733767L;
  public static final String XML_TAG = "Allocation";
  public static final int MENU_CONNECTION_LIST = 0;
  public static final int MENU_SERVER_CONFIG_MANAGER = 1;
  public static final int MENU_FUNCTION_MANAGER = 2;
  public static final int MENU_GLOBAL_PARAMETER = 3;
  public static final int MENU_PRIVILEGE_MANAGER = 4;
  public static final int MENU_EDIT_PRINTER_GROUP = 5;
  public static final int MENU_SCHEDULED_REPORT = 6;
  public static final int MENU_GLOBAL_TABLEDATA = 7;
  public static final int MENU_GLOBAL_DICTIONARY = 8;
  public static final int MENU_FACE_MANAGER = 9;
  public static final int MENU_STYLE_LIST = 10;
  public static final int MENU_GLOBAL_DATALIST = 11;
  public static final int MENU_GLOBAL_WIDGET = 12;
  private IntList serverMenuList = new IntList();
  private List connectionList = new ArrayList();
  private List serverDSList = new ArrayList();
  private List serverDicList = new ArrayList();
  private FileFragList designList = new FileFragList();
  private FileFragList viewList = new FileFragList();
  private FileFragList formList = new FileFragList();
  private FileFragList writeList = new FileFragList();
  private static final String SEPARATER_STRING = ".,;";

  public void addServerMenu(int paramInt)
  {
    if (this.serverMenuList.contain(paramInt))
      return;
    this.serverMenuList.add(paramInt);
  }

  public int getServerMenuCount()
  {
    return this.serverMenuList.size();
  }

  public int getServerMunu(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= getServerMenuCount()))
      return -1;
    return this.serverMenuList.get(paramInt);
  }

  public void clearServerMenu()
  {
    this.serverMenuList.clear();
  }

  public void removeServerMenu(int paramInt)
  {
    int i = this.serverMenuList.indexOf(paramInt);
    if (i > -1)
      this.serverMenuList.remove(i);
  }

  public void addConnection(String paramString)
  {
    if (!(this.connectionList.contains(paramString)))
      this.connectionList.add(paramString);
  }

  public int getConnectionCount()
  {
    return this.connectionList.size();
  }

  public String getConnection(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= getConnectionCount()))
      return null;
    return ((String)this.connectionList.get(paramInt));
  }

  public void clearConnection()
  {
    this.connectionList.clear();
  }

  public void removeConnection(String paramString)
  {
    this.connectionList.remove(paramString);
  }

  public void addServerDS(String paramString)
  {
    if (!(this.serverDSList.contains(paramString)))
      this.serverDSList.add(paramString);
  }

  public int getServerDSCount()
  {
    return this.serverDSList.size();
  }

  public String getServerDS(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= getServerDSCount()))
      return null;
    return ((String)this.serverDSList.get(paramInt));
  }

  public void clearServerDS()
  {
    this.serverDSList.clear();
  }

  public void removeServerDS(String paramString)
  {
    this.serverDSList.remove(paramString);
  }

  public void addServerDic(String paramString)
  {
    if (!(this.serverDicList.contains(paramString)))
      this.serverDicList.add(paramString);
  }

  public int getServerDicCount()
  {
    return this.serverDicList.size();
  }

  public String getServerDic(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= getServerDicCount()))
      return null;
    return ((String)this.serverDicList.get(paramInt));
  }

  public void clearServerDic()
  {
    this.serverDicList.clear();
  }

  public void removeServerDic(String paramString)
  {
    this.serverDicList.remove(paramString);
  }

  public void addDesign(FileFrag paramFileFrag)
  {
    if (!(this.designList.contains(paramFileFrag)))
      this.designList.addFileFrag(paramFileFrag);
  }

  public void addDesign(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        addDesign(paramArrayOfFileFrag[i]);
  }

  public int getDesignCount()
  {
    return this.designList.size();
  }

  public FileFrag getDesign(int paramInt)
  {
    return this.designList.getFileFrag(paramInt);
  }

  public void clearDesign()
  {
    this.designList.clear();
  }

  public void removeDesign(FileFrag paramFileFrag)
  {
    this.designList.remove(paramFileFrag);
  }

  public void removeDesign(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        removeDesign(paramArrayOfFileFrag[i]);
  }

  public void addView(FileFrag paramFileFrag)
  {
    if (!(this.viewList.contains(paramFileFrag)))
      this.viewList.addFileFrag(paramFileFrag);
  }

  public void addView(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        addView(paramArrayOfFileFrag[i]);
  }

  public int getViewCount()
  {
    return this.viewList.size();
  }

  public FileFrag getView(int paramInt)
  {
    return this.viewList.getFileFrag(paramInt);
  }

  public void clearView()
  {
    this.viewList.clear();
  }

  public void removeView(FileFrag paramFileFrag)
  {
    this.viewList.remove(paramFileFrag);
  }

  public void removeView(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        removeView(paramArrayOfFileFrag[i]);
  }

  public void addForm(FileFrag paramFileFrag)
  {
    if (!(this.formList.contains(paramFileFrag)))
      this.formList.addFileFrag(paramFileFrag);
  }

  public void addForm(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        addForm(paramArrayOfFileFrag[i]);
  }

  public int getFormCount()
  {
    return this.formList.size();
  }

  public FileFrag getForm(int paramInt)
  {
    return this.formList.getFileFrag(paramInt);
  }

  public void clearForm()
  {
    this.formList.clear();
  }

  public void removeForm(FileFrag paramFileFrag)
  {
    this.formList.remove(paramFileFrag);
  }

  public void removeForm(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        removeForm(paramArrayOfFileFrag[i]);
  }

  public void addWrite(FileFrag paramFileFrag)
  {
    if (!(this.writeList.contains(paramFileFrag)))
      this.writeList.addFileFrag(paramFileFrag);
  }

  public void addWrite(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        addWrite(paramArrayOfFileFrag[i]);
  }

  public int getWriteCount()
  {
    return this.writeList.size();
  }

  public FileFrag getWrite(int paramInt)
  {
    return this.writeList.getFileFrag(paramInt);
  }

  public void clearWrite()
  {
    this.writeList.clear();
  }

  public void removeWrite(FileFrag paramFileFrag)
  {
    this.writeList.remove(paramFileFrag);
  }

  public void removeWrite(FileFrag[] paramArrayOfFileFrag)
  {
    int i;
    if ((paramArrayOfFileFrag != null) && (paramArrayOfFileFrag.length > 0))
      for (i = 0; i < paramArrayOfFileFrag.length; ++i)
        removeWrite(paramArrayOfFileFrag[i]);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      clearServerMenu();
      clearServerDS();
      clearServerDic();
      clearConnection();
      clearDesign();
      clearView();
      clearForm();
      clearWrite();
    }
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      Object localObject;
      int i;
      String str2 = paramXMLableReader.getTagName();
      if ("ServerMenus".equals(str2))
      {
        if ((str1 = paramXMLableReader.getElementValue()) == null)
          return;
        localObject = str1.split(",");
        i = 0;
        while (true)
        {
          if (i >= localObject.length)
            return;
          addServerMenu(Integer.parseInt(localObject[i]));
          ++i;
        }
      }
      if ("Connections".equals(str2))
      {
        if ((str1 = paramXMLableReader.getElementValue()) == null)
          return;
        localObject = str1.split(".,;");
        i = 0;
        while (true)
        {
          if (i >= localObject.length)
            return;
          addConnection(localObject[i]);
          ++i;
        }
      }
      if ("ServerDSs".equals(str2))
      {
        if ((str1 = paramXMLableReader.getElementValue()) == null)
          return;
        localObject = str1.split(".,;");
        i = 0;
        while (true)
        {
          if (i >= localObject.length)
            return;
          addServerDS(localObject[i]);
          ++i;
        }
      }
      if ("ServerDics".equals(str2))
      {
        if ((str1 = paramXMLableReader.getElementValue()) == null)
          return;
        localObject = str1.split(".,;");
        i = 0;
        while (true)
        {
          if (i >= localObject.length)
            return;
          addServerDic(localObject[i]);
          ++i;
        }
      }
      if ("Designs".equals(str2))
      {
        localObject = readFileFrags(paramXMLableReader);
        addDesign(localObject);
      }
      else if ("Views".equals(str2))
      {
        localObject = readFileFrags(paramXMLableReader);
        addView(localObject);
      }
      else if ("Forms".equals(str2))
      {
        localObject = readFileFrags(paramXMLableReader);
        addForm(localObject);
      }
      else if ("Writes".equals(str2))
      {
        localObject = readFileFrags(paramXMLableReader);
        addWrite(localObject);
      }
    }
  }

  private FileFrag[] readFileFrags(XMLableReader paramXMLableReader)
  {
    FileFragList localFileFragList = new FileFragList();
    paramXMLableReader.readXMLObject(new XMLReadable(this, localFileFragList)
    {
      private final FileFragList val$ffList;
      private final Allocation this$0;

      public void readXML()
      {
        if ("FileFrag".equals(paramXMLableReader.getTagName()))
        {
          FileFrag localFileFrag = new FileFrag();
          paramXMLableReader.readXMLObject(localFileFrag);
          this.val$ffList.addFileFrag(localFileFrag);
        }
      }
    });
    return localFileFragList.toArray();
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    Object localObject;
    int i;
    int j;
    paramXMLPrintWriter.startTAG("Allocation");
    if (this.serverMenuList.size() > 0)
    {
      localObject = this.serverMenuList.toString();
      paramXMLPrintWriter.startTAG("ServerMenus").textNode(((String)localObject).substring(1, ((String)localObject).length() - 1)).end();
    }
    if (this.connectionList.size() > 0)
    {
      localObject = new StringBuffer();
      for (j = 0; j < this.connectionList.size(); ++j)
      {
        if (j != 0)
          ((StringBuffer)localObject).append(".,;");
        ((StringBuffer)localObject).append(this.connectionList.get(j));
      }
      paramXMLPrintWriter.startTAG("Connections").textNode(((StringBuffer)localObject).toString()).end();
    }
    if (this.serverDSList.size() > 0)
    {
      localObject = new StringBuffer();
      for (j = 0; j < this.serverDSList.size(); ++j)
      {
        if (j != 0)
          ((StringBuffer)localObject).append(".,;");
        ((StringBuffer)localObject).append(this.serverDSList.get(j));
      }
      paramXMLPrintWriter.startTAG("ServerDSs").textNode(((StringBuffer)localObject).toString()).end();
    }
    if (this.serverDicList.size() > 0)
    {
      localObject = new StringBuffer();
      for (j = 0; j < this.serverDicList.size(); ++j)
      {
        if (j != 0)
          ((StringBuffer)localObject).append(".,;");
        ((StringBuffer)localObject).append(this.serverDicList.get(j));
      }
    }
    if (this.designList.size() > 0)
    {
      paramXMLPrintWriter.startTAG("Designs");
      for (i = 0; i < this.designList.size(); ++i)
        this.designList.getFileFrag(i).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.viewList.size() > 0)
    {
      paramXMLPrintWriter.startTAG("Views");
      for (i = 0; i < this.viewList.size(); ++i)
        this.viewList.getFileFrag(i).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.formList.size() > 0)
    {
      paramXMLPrintWriter.startTAG("Forms");
      for (i = 0; i < this.formList.size(); ++i)
        this.formList.getFileFrag(i).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.writeList.size() > 0)
    {
      paramXMLPrintWriter.startTAG("Writes");
      for (i = 0; i < this.writeList.size(); ++i)
        this.writeList.getFileFrag(i).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  private void add(String paramString1, String paramString2)
  {
    int i;
    int j;
    String[] arrayOfString = paramString1.split(",");
    if ("view".equals(paramString2))
    {
      i = 0;
      j = arrayOfString.length;
      while (true)
      {
        if (i >= j)
          return;
        addView(new FileFrag(arrayOfString[i]));
        ++i;
      }
    }
    if ("write".equals(paramString2))
    {
      i = 0;
      j = arrayOfString.length;
      while (true)
      {
        if (i >= j)
          return;
        addWrite(new FileFrag(arrayOfString[i]));
        ++i;
      }
    }
    if ("form".equals(paramString2))
    {
      i = 0;
      j = arrayOfString.length;
      while (true)
      {
        if (i >= j)
          return;
        addForm(new FileFrag(arrayOfString[i]));
        ++i;
      }
    }
    if ("design".equals(paramString2))
    {
      i = 0;
      j = arrayOfString.length;
      while (i < j)
      {
        addDesign(new FileFrag(arrayOfString[i]));
        ++i;
      }
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Allocation localAllocation = (Allocation)super.clone();
    IntList localIntList = new IntList();
    for (int i = 0; i < this.serverMenuList.size(); ++i)
      localIntList.add(this.serverMenuList.get(i));
    localAllocation.serverMenuList = localIntList;
    ArrayList localArrayList1 = new ArrayList();
    for (int j = 0; j < this.connectionList.size(); ++j)
      localArrayList1.add(this.connectionList.get(j));
    localAllocation.connectionList = localArrayList1;
    ArrayList localArrayList2 = new ArrayList();
    for (int k = 0; k < this.serverDSList.size(); ++k)
      localArrayList2.add(this.serverDSList.get(k));
    localAllocation.serverDSList = localArrayList2;
    ArrayList localArrayList3 = new ArrayList();
    for (int l = 0; l < this.serverDicList.size(); ++l)
      localArrayList3.add(this.serverDicList.get(l));
    localAllocation.serverDicList = localArrayList3;
    FileFragList localFileFragList1 = new FileFragList();
    for (int i1 = 0; i1 < this.designList.size(); ++i1)
      localFileFragList1.addFileFrag((FileFrag)this.designList.getFileFrag(i1).clone());
    localAllocation.designList = localFileFragList1;
    FileFragList localFileFragList2 = new FileFragList();
    for (int i2 = 0; i2 < this.viewList.size(); ++i2)
      localFileFragList2.addFileFrag((FileFrag)this.viewList.getFileFrag(i2).clone());
    localAllocation.viewList = localFileFragList2;
    FileFragList localFileFragList3 = new FileFragList();
    for (int i3 = 0; i3 < this.formList.size(); ++i3)
      localFileFragList3.addFileFrag((FileFrag)this.formList.getFileFrag(i3).clone());
    localAllocation.formList = localFileFragList3;
    FileFragList localFileFragList4 = new FileFragList();
    for (int i4 = 0; i4 < this.writeList.size(); ++i4)
      localFileFragList4.addFileFrag((FileFrag)this.writeList.getFileFrag(i4).clone());
    localAllocation.writeList = localFileFragList4;
    return localAllocation;
  }
}